package cae.appBar.buttons
{
	import mx.controls.Button;
	import flash.events.MouseEvent;
	import mx.containers.Canvas;
	import mx.containers.VBox;
	import mx.containers.HBox;
	import mx.controls.Label;
	import mx.managers.PopUpManager;
	import flash.geom.Point;
	import mx.core.Application;
	import flash.ui.Mouse;
	import flash.display.DisplayObject;
	import mx.controls.Alert;
	import mx.controls.LinkBar;
	import mx.collections.ArrayCollection;
	import mx.events.ListEvent;
	import mx.events.ItemClickEvent;
	import mx.effects.WipeDown;
	import caurina.transitions.Equations;
	import mx.effects.Move;
	import mx.effects.Resize;
	import mx.controls.MenuBar;
	import flash.events.Event;
	import cae.skins.CustomContainerBorderSkinB;
	import cae.bigmenu.CaeMenuBig;
	import mx.containers.Box;
	import mx.skins.halo.LinkSeparator;
	import cae.appBar.CaeISelectableButton;
	import cae.windows.CaeWindowEvent;

	[Event(name="OPEN",type="cae.windows.CaeWindowEvent")]

	public class CaeMenuButton extends HBox implements CaeISelectableButton
	{
		public var _dataProvider:XML;
		private var l:Label;
		
		public var _selected:Boolean = false;
		private var over:Boolean = false;
		
		public function CaeMenuButton()
		{
			addEventListener(MouseEvent.MOUSE_OVER, mouseOver);
			addEventListener(MouseEvent.MOUSE_OUT, mouseOut);
			addEventListener(MouseEvent.CLICK, openOption);
			
			setSkin();
		}
		
		override protected function createChildren():void
		{
			super.createChildren();
			
			if (!l)
			{
				l = new Label();
				l.text = label;
				addChild(l);
			}
			
			
		}
		
		public function set dataProvider(dp:XML):void
		{
			_dataProvider = dp;
		}
		
		public function get dataProvider():XML
		{
			return _dataProvider;
		}
		
		public function set selected(s:Boolean):void
		{
			_selected = s;
			setSkin();
		}
		
		public function get selected():Boolean
		{
			return _selected;
		}
		
		public function setSkin():void
		{
			if(!over)
			{
				if(selected)
				{
					alpha = 0;
					
					styleName = "menuTabSelected";
				}
				else
				{
					alpha = 0;
					styleName = "menuTabNotOpen";
				}
			}
			else
			{
				alpha = 1;
				styleName = "menuButtonOver";
			}
		}

		private function mouseOver(e:MouseEvent):void
		{
			if(!over)
			{
				over = true;
				setSkin();
			}
		}
		
		private function mouseOut(e:MouseEvent = null):void
		{
			over = false;
			setSkin();
		}	
		
		private function openOption(e:MouseEvent):void
		{
			dispatchEvent(new CaeWindowEvent(CaeWindowEvent.OPEN, dataProvider.@ventana, dataProvider.@label, dataProvider.@dataId, true));
		}
	}
}